package cn.gson.springboot.model.pojos;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;

@Entity
@Table(name = "storage_detail", schema = "crm")
public class StorageDetail {
    private int storageDetailId;
    private Integer storageDetailNum;
    private String storageDetailNote;
    private Product productByProductId;
    private Storage storageByStorageId;
    private List<InventoryFlow>  inventoryFlowsByStorageDetailId;

    @Id
    @Column(name = "storage_detail_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY,generator = "seq")
    public int getStorageDetailId() {
        return storageDetailId;
    }

    public void setStorageDetailId(int storageDetailId) {
        this.storageDetailId = storageDetailId;
    }


    @Basic
    @Column(name = "storage_detail_num", nullable = true)
    public Integer getStorageDetailNum() {
        return storageDetailNum;
    }

    public void setStorageDetailNum(Integer storageDetailNum) {
        this.storageDetailNum = storageDetailNum;
    }

    @Basic
    @Column(name = "storage_detail_note", nullable = true, length = 255)
    public String getStorageDetailNote() {
        return storageDetailNote;
    }

    public void setStorageDetailNote(String storageDetailNote) {
        this.storageDetailNote = storageDetailNote;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        StorageDetail that = (StorageDetail) o;
        return storageDetailId == that.storageDetailId &&
                Objects.equals(storageDetailNum, that.storageDetailNum) &&
                Objects.equals(storageDetailNote, that.storageDetailNote);
    }

    @Override
    public int hashCode() {
        return Objects.hash(storageDetailId, storageDetailNum, storageDetailNote);
    }

    @ManyToOne
    @JoinColumn(name = "product_id", referencedColumnName = "product_id")
    public Product getProductByProductId() {
        return productByProductId;
    }

    public void setProductByProductId(Product productByProductId) {
        this.productByProductId = productByProductId;
    }

    @ManyToOne
    @JoinColumn(name = "storage_id", referencedColumnName = "storage_id")
    public Storage getStorageByStorageId() {
        return storageByStorageId;
    }

    public void setStorageByStorageId(Storage storageByStorageId) {
        this.storageByStorageId = storageByStorageId;
    }

    @OneToMany(mappedBy = "stoDetailByStoDetailId",cascade={CascadeType.PERSIST,CascadeType.REMOVE})
    public List<InventoryFlow> getInventoryFlow() {
        return inventoryFlowsByStorageDetailId;
    }

    public void setInventoryFlow(List<InventoryFlow> inventoryFlowsByStorageDetailId) {
        this.inventoryFlowsByStorageDetailId = inventoryFlowsByStorageDetailId;
    }

}
